$(document).ready(function(){
	$("table.dtable tr").each(function(){
		$(this).mouseover(function(){
			$(this).children("td").each(function(){
				$(this).css("background-color", "#F2F4E7");
			});
		});
		
		$(this).mouseout(function(){
			$(this).children("td").each(function(){
				$(this).css("background-color", "");
			});
		});
		
		// $(this).click(function(){
			// var td1 = $(this).children("td:eq(0)");
			// var chk = $(td1).children("input:checkbox");
			// if(chk){
				// if($(chk).attr('checked')){
				// $(chk).removeAttr('checked');
				// }
				// else {
					// $(chk).attr('checked', 'checked');
				// }
			// }
		// });
	});
	
	loadSorted();
});

function setMainFrameUrl(url){
	window.top.main.location = url; 
}

/**
 * 转换高亮tab 
 * @param {Object} id
 */
function turnHighLight(id){
	if(id){
		$(".tab ul li a").each(function(){
			if(this.id == id){
				$(this).attr("class", "here");
			}
			else {
				$(this).removeAttr("class");
			}
		});	
	}
}

/**
 * 排序
 * @param th
 * @param formId
 * @param field
 * @param orderCtl
 */
function sortField(th, formId, field, orderCtl){
	var formCtl = document.getElementById(formId);
	var fieldCtl = document.getElementById('sort.field');
	var orderCtl = document.getElementById('sort.order');
	
	if(!th || !formCtl || !fieldCtl || !orderCtl){
		return; 
	}
	
	var order = 'desc';
	if($(th).attr('class') == 'up'){
		order = 'asc';
	}
	
	orderCtl.value = order;
	fieldCtl.value = field;
	formCtl.submit();
}

/**
 * 加载排序样式
 */
function loadSorted(){
	var fieldCtl = document.getElementById('sort.field');
	var orderCtl = document.getElementById('sort.order');
	if(!fieldCtl || !orderCtl){
		return;
	}
	$(".dtable tr th").each(function(){
		var id = this.id;
		if(id && id == fieldCtl.value + '_sort'){
			if(orderCtl.value == 'desc'){
				$(this).attr('class', 'up');
			}
			else{
				$(this).attr('class', 'down');
			}
		}
	});
}

/**
 * 用于下载远程图片
 * 
 * @author Gao Youbo
 * @since 2013-07-26
 */
function downloadRemoteImages(fid, ftype, content, callback) {
	$.post(mlog.variable.base + '/admin/attachment/remote', {
		fid : fid,
		ftype : ftype,
		content : content
	}, function(response) {
		callback(response);
	});
}